package accepttests;

import database.UIDManger;
import sessionManager.SessionManager;
import user.UserIF;
import user.blog.Blog;
import user.blog.BlogIF;
import user.blog.post.Post;

public class RemoveUserFacade {
	private SessionManager session;
	
	public RemoveUserFacade() {
		session = SessionManager.getInstance();
	}
	
	public void loadData() {
		// TODO
	}
	
	public String logon(String login, String password) throws Exception {
		return session.loginUser(login, password);
	}
	
	public String createBlog(String sessionId, String title, String description) throws Exception {
		UserIF user = session.getUserBySessionID(sessionId);
		//BlogIF blog = new Blog(UIDManger.getValidBlgoID(), sessionId, title, description);
		//user.getBlogs().add(blog);
		String id = user.createBlog(sessionId, title, description);
		user.save();
		return id;
	}
	
	public String createPost(String sessionId, String blogId, String title, String text) throws Exception {
		UserIF user = session.getUserBySessionID(sessionId);
		//System.out.println("sessionId: " + sessionId + " blogId: " + blogId + " Title: " + title + "Text: " + text);
		//System.out.println("****");
		Post post = new Post(sessionId, blogId, title, text);
		//System.out.println("sessionId: " + sessionId + " blogId: " + blogId + " Title: " + title + "Text: " + text);
		String id = user.getBlogByBID(blogId).addPost(post);
		user.getBlogByBID(blogId).savePosts();
		user.save();
		return id;
	}
	
	public void deleteProfile(String sessionId) throws Exception {
		session.removeUser(sessionId);
	}
	
	public String getNumberOfPosts(String blogId) throws Exception {
		return session.getBlogByBID(blogId).getBlogID();
	}
	
	public void saveData() {
		// TODO
	}
}